<%@ page import="sistema.Venda" %>
<!doctype html>
<html>
  <head>
    <meta name="layout" content="main">
  <g:set var="entityName" value="${message(code: 'venda.label', default: 'Venda')}" />
  <title><g:message code="default.create.label" args="[entityName]" /></title>
</head>
<body>
  <a href="#edit-venda" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
  <div class="nav" role="navigation">
    <ul>
      <li><g:link class="home" controller="admin" action="index">Home</g:link></li>
      <li><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
      <li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
    </ul>
  </div>
  <div id="edit-venda" class="content scaffold-edit" role="main">
    <h1><g:message code="default.edit.label" args="[entityName]" /></h1>
    <g:if test="${flash.message}">
      <div class="message" role="status">${flash.message}</div>
    </g:if>
    <g:hasErrors bean="${vendaInstance}">
      <ul class="errors" role="alert">
        <g:eachError bean="${vendaInstance}" var="error">
          <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
        </g:eachError>
      </ul>
    </g:hasErrors>
    <div id="editProd">
      <div id="conteudo" style="margin: 20px 0 10px 20px">
        <g:form method="post" >
          <g:hiddenField name="version" value="${vendaInstance?.version}" />
          <g:hiddenField name="id" value="${vendaInstance?.id}" />
          <fieldset class="form">
            <h3>  
              Vendedor: <g:link controller="vendedor" action="show" id="${vendaInstance?.vendedor?.id}">${vendaInstance?.vendedor?.encodeAsHTML()}</g:link>
              </br>
              Data Venda:  <g:formatDate format="dd/MM/yyyy" date="${vendaInstance?.dateCreated}" />
            </h3>
            <table id="newspaper-a">
              <thead>
                <tr>
                  <th scope="col">Cod Barra</th>
                  <th scope="col">Categoria</th>
                  <th scope="col">Cor</th>
                  <th scope="col">Modelo</th>
                  <th scope="col">QTD</th>
                  <th scope="col">Custo Varejo</th>
                  <th scope="col">Custo Soma</th>
                  <th scope="col">Remover Item</th>
                </tr>
              </thead>
              <tbody>
              <g:each in="${listProd}">
                <tr>
                  <g:hiddenField name="codBarra" value="${it.produto.codBarra}"/>
                  <td>${it.produto.codBarra}</td>
                  <td>${it.produto.categoria}</td>
                  <td>${it.produto.cor}</td>
                  <td>${it.produto.modelo}</td>
                  <td> <input style="width: 50px" type="text" name="total" maxlength="3" value="${it.qtdProduto}"/></td>
                  <td style="text-align: right"><g:moeda valor="${it.produto.custoVarejo}"/></td>
                <td style="text-align: right"><g:moeda valor="${it.valorTotalProd}"/></td>
                <td style="text-align: center">
                <g:remoteLink controller="venda" 
                              action="excluirProduto"  
                              id="${it.id}" 
                              update="editProd">x</g:remoteLink>
                </td>
                </tr>
              </g:each>
              </tbody>
              <thead>
                <tr>
                  <th></th>
                  <th></th>
                  <th></th>
                  <th></th>
                  <th></th>
                  <th></th>
                  <th scope="col">TOTAL DA COMPRA</th>
                  <th style="text-align: right;"><g:moeda valor="${vendaInstance.valorTotal}" /></th>
              </tr>
              </thead>
            </table>
            <g:link title="ADICIONAR MAIS PRODUTOS" controller="venda" action="novosProdutos" id="${vendaInstance.id}">
              <img width="40" src="${resource(dir:'images', file:'plus.png')}"/>
            </g:link>
          </fieldset>
          <fieldset class="buttons">
            <g:actionSubmit class="save" action="update" value="Atualizar" />
            <g:actionSubmit class="list" action="list" value="Retornar" />
            <g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" formnovalidate="" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
          </fieldset>
        </g:form>
      </div>
    </div>
  </div>
</body>
</html>
